package com.chen.aliyunsms.controller;

import com.chen.aliyunsms.utils.SmsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/sms")
public class SmsController {

    @Autowired
    private SmsUtil smsUtil;

    @Value("${aliyun.sms.template_code}")
    private String template_code;//模板编号

    @Value("${aliyun.sms.sign_name}")
    private String sign_name;//签名

    @PostMapping("/send")
    public boolean sendSms(Map<String,String> map){
        try {
            smsUtil.sendSms(map.get("mobile"),template_code,sign_name,map.get("code"));
            return true;
        } catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }

}
